#pragma once


#include "Space.h"
#include "Vector.h"
#include <string>
/*
  Copyright 2008 by Alexey Solovyev and University of Pittsburgh
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

namespace org
{
	namespace spark
	{
		
		namespace space
		{
			class Space;
			class SpaceAgent; 
			//using org::spark::space::Space;
			//using org::spark::math::Vector;
			//using org::spark::math::Vector4d;

			
			/// <summary>
			/// The basic space node class 
			/// </summary>
			class SpaceNode 
			{
				/// <summary>
				/// Default serialVersionUID
				/// </summary>
			private:
				//static const long long serialVersionUID = 1LL;

				/* A reference to space where this node exists */
			protected:
				
			public:
				bool nodeIsRemoved;
				Space *space;

				// Auxiliary references for fast query operation
				SpaceNode *next;
				SpaceNode *prev;

				// The agent associated with this space node
				SpaceAgent *agent;

				// Current position
				Vector *position;
				// Vector for changing the position
				Vector *newPosition;


				// Which action to perform on this node
				int state;

				// Indicates that the node was removed from the space

			protected:
				static const int NODE_IS_CREATING = 0x1;
				static const int NODE_IS_REMOVING = 0x2;
				static const int NODE_IS_MOVING = 0x4;
				// Old position
			//	protected Vector		oldPosition;

				


				/// <summary>
				/// Returns node's shape code
				/// @return
				/// </summary>
			public:

				SpaceNode();
				/// <summary>
				/// The default constructor </summary>
				/// <param name="space"> </param>
				SpaceNode(Space *space);

				virtual int getShape() = 0;

				/// <summary>
				/// Gets the current position
				/// @return
				/// </summary>
				virtual Vector *getPosition();


				/// <summary>
				/// Returns node's space
				/// @return
				/// </summary>
				virtual Space *getSpace();


				/// <summary>
				/// Gets the new position
				/// @return
				/// </summary>
				virtual Vector *getNewPosition();

				/// <summary>
				/// Associates the agent with the node </summary>
				/// <param name="agent"> </param>
			protected:
				virtual void AssociateAgent(SpaceAgent *agent);

				/// <summary>
				/// Sets the random position
				/// </summary>
			public:
				virtual void setRandomPosition();


				/// <summary>
				/// Moves the node to the position v </summary>
				/// <param name="v"> </param>
				virtual void jump(Vector *v);

				/// <summary>
				/// Changes the position by the vector dv </summary>
				/// <param name="dv"> </param>
				virtual void move(Vector *dv);

				/// <summary>
				/// Tests whether two nodes intersect </summary>
				/// <param name="node">
				/// @return </param>
				virtual bool intersects(SpaceNode *node) = 0;


				/// <summary>
				/// A method for testing an intersection with a circle </summary>
				/// <param name="node">
				/// @return </param>
				virtual bool intersectsWith(CircleNode *node) = 0;
				/// <summary>
				/// A method for testing an intersection with a (visual) square </summary>
				/// <param name="node">
				/// @return </param>
				virtual bool intersectsWith(SquareNode *node) = 0;
			protected:
				


				


				/// <summary>
				/// A method for testing an intersection with a square </summary>
				/// <param name="node">
				/// @return </param>
				//virtual bool intersectsWith(Square2Node *node) = 0;


				/// <summary>
				/// Returns the relative size of the node
				/// @return
				/// </summary>
			public:
				virtual double getRelativeSize();


				//*********************
				// Rendering interface
				//*********************

				// Node's color
			protected:
				//Vector4d *color;

				// Rotation parameter
				double rotation;


			public:
				//virtual void setColor(Vector *color);


				//virtual void setColor(Vector4d *color);


				//virtual Vector4d *getColor();


				virtual Vector *getColor3();


				virtual double getAlpha();


				virtual void setAlpha(double a);


				virtual Vector *getRGBColor();


				virtual void setRotation(double theta);

				virtual void addRotation(double dtheta);

				virtual double getRotation();


				virtual std::string ToString();

			private:
				void InitializeInstanceFields();
			};

		}
	}
}
